/*
 *   Copyright 2021 zzh
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.aduib.boot.logging.access.handler;

import com.aduib.boot.logging.appender.LogAppender;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description: AccessLogHandler
 * @author: zzh
 * @date: 2021/9/16 09:52
 */
public interface AccessLogHandler<T> extends LogAppender<T> {
  /**
   * 处理日志
   * @param request
   * @param response
   * @param executionTime
   * @param throwable
   */
  default void handleLog(HttpServletRequest request, HttpServletResponse response,long executionTime,Throwable throwable){
    T t = buildLog(request, response, executionTime, throwable);
    saveLog(t);
  }

  /**
   * 创建日志
   * @param request
   * @param response
   * @param executionTime
   * @param throwable
   * @return
   */
  T buildLog(HttpServletRequest request, HttpServletResponse response,long executionTime,Throwable throwable);

  /**
   * 保存日志
   * @param t
   */
  @Override
  void saveLog(T t);
}
